package com.guoxin.designpattern.chapter1;

/**
 * 单例模式，双重验锁，线程安全
 * 
 * @author guoxin
 * @date 2019年8月26日
 */
public class SingletonObject5 {
	private static volatile SingletonObject5 instance;

	private SingletonObject5() {
		// empty
	}

	/**
	 * double check add volatile
	 */
	public static SingletonObject5 getInstance() {
		if (instance == null) {
			synchronized (SingletonObject5.class) {
				if (instance == null) {
					instance = new SingletonObject5();
				}
			}
		}
		return instance;
	}
}
